<?php

namespace App\Supports\Payment\Channels;

use AdaPay\AdaPay;
use AdaPaySdk\AdaPayCommon;
use AdaPaySdk\Refund;
use AdaPaySdk\Payment;
use AdaPaySdk\AdapayTools;
use App\Supports\Payment\Contracts\Channel;
use App\Supports\Payment\Contracts\PayChannel;

class AdaWxmini extends Channel implements PayChannel
{
	public function __construct()
	{
		$this->channelName = 'adawxmini';

		$this->setConfig();
		$this->setOrigin();
	}

	public function setConfig()
	{
        $route = cs()->adapay_route;
		$this->config = config("adapay.{$route}");
	}

	public function setOrigin()
	{
		// TODO: Implement setOrigin() method.
	}

	public function getChannelName()
	{
		return $this->channelName;
	}

	public function tools($data = null)
	{
		include_once dirname(__FILE__).'/../Channels/Adapay/AdapaySdk/init.php';
		AdaPay::init($this->config, 'live', true);
		return new AdapayTools();
	}

	public function verify($data = null)
	{
		// TODO: Implement verify() method.
	}

	public function find($data = null)
	{
		// TODO: Implement find() method.
	}

	public function pay($data = null)
	{
		include_once dirname(__FILE__).'/../Channels/Adapay/AdapaySdk/init.php';
		AdaPay::init($this->config, 'live', true);

		$returnUrl = app()->environment('production')
			? 'https://wap.pandago.shop/#/packs/pages/order/paid'
			: 'https://dwap.pandago.shop/#/packs/pages/order/paid';

		$data['callback_url'] = $returnUrl;

		$adaCommon = new AdaPayCommon();
		$adaCommon->requestAdapay($data);
		return $adaCommon;
	}

	public function refund($data = null)
	{
		include_once dirname(__FILE__).'/../Channels/Adapay/AdapaySdk/init.php';
		AdaPay::init($this->config, 'live', true);

		$refund = new Refund();
		$refund->create($data);
		return $refund;
	}

	public function transfer($data = null)
	{
		// TODO: Implement transfer() method.
	}

	public function query($data = null)
	{
		// TODO: Implement query() method.
	}
}
